﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
//add for using Modify Web.Config
using System.Web.Configuration;

public partial class admin_UpdateWeekShow : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            this.calFrom.Visible = false;
            this.calTo.Visible = false;
            this.lblCalFrom.Text = this.GetConfig("startshow");
            this.lblCalTo.Text = this.GetConfig("endshow");
        }
    }
    protected void imgCalTo_Click(object sender, ImageClickEventArgs e)
    {
        if (this.calTo.Visible == true)
            this.calTo.Visible = false;
        else
            this.calTo.Visible = true;
    }
    protected void imgCalFrom_Click(object sender, ImageClickEventArgs e)
    {
        if (this.calFrom.Visible == true)
            this.calFrom.Visible = false;
        else
            this.calFrom.Visible = true;
    }
    protected void calFrom_SelectionChanged(object sender, EventArgs e)
    {
        UpdateConfig("startshow", this.calFrom.SelectedDate.ToShortDateString());
        this.lblCalFrom.Text = this.calFrom.SelectedDate.ToShortDateString();
    }
    protected void calTo_SelectionChanged(object sender, EventArgs e)
    {
        UpdateConfig("endshow", this.calTo.SelectedDate.ToShortDateString());
        this.lblCalTo.Text = this.calTo.SelectedDate.ToShortDateString();
    }

    private void UpdateConfig(string strKey, string strValue)
    {
        Configuration objConfig = WebConfigurationManager.OpenWebConfiguration("~");
        AppSettingsSection objAppsettings = (AppSettingsSection)objConfig.GetSection("appSettings");
        if (objAppsettings != null)
        {
            objAppsettings.Settings[strKey].Value = strValue;
            objConfig.Save();
        }
    }
    private string GetConfig(string strKey)
    {
        string str = ConfigurationManager.AppSettings.GetValues(strKey)[0];
        return str;
    }

}
